<template>
	<view>
		
		<view class="bg-gray -openDoor-body">
			<view class="roomInfo">
				<view class="d-flex a-center">
					<view style="margin:5px;color:#3e71ff;" class="d-flex a-center">
						<uni-icons type='shop-filled' size="30" color="#3e71ff"></uni-icons>
						<text>{{cData.name || '读取中...'}}</text>
					</view>
				</view>
			</view>
			
			<view class="d-flex a-center j-center" style="height:45vh;background-color: #e7e7e7;">
				其他内容预留 {{canOpenDoor}}
			</view>
		</view>

		

		<!-- 底部菜单 -->
		<globalMenu ref="gm" @onLoginStatusChange="onLSC" :options="thisOpts" :canOpenDoor="canOpenDoor"></globalMenu>
	</view>
</template>

<script>
	import globalMenu from '@/components/global-menu.vue'
	import com from '../common/index.js'
	export default {
		components: {
			globalMenu
		},
		data() {
			return {
				userInfo: {},
				thisOpts: {},
				cData: {}, //书室信息
				canOpenDoor: false, //是否具备开门条件(显示开门按钮而不是扫码开门)
			}
		},
		onShow() {
			//更新用户信息
			this.$refs.gm.userDataUpdate()
		},
		onLoad(opts) {
			const that = this
			//取参数 c书室id t是类型1是开门，2是自助机登录 M是mid
			//获取书室信息
			if (uni.getSystemInfoSync().uniPlatform === 'mp-weixin') {
				const data = decodeURIComponent(opts.scene).split('?');
				if (data) {
					let ps = com.parseQueryString(data[0])
					console.log('扫码进入', ps);
					that.thisOpts = ps
					//取书室信息					
					that.getPageData(ps.c)
				}
			}
		},
		methods: {
			onLSC(e){
				console.log('e:',e)
			},
			//获取页面信息
			getPageData(roomID) {
				const that = this
				com.poster(
					"/mapi/scan-code/get-content?id=" + roomID, {}, "get", (e) => {
						//console.log(e)
						if (e.code !== 200) {
							uni.showToast('获取书室信息出错')
							return
						}
						that.cData = e.data
						//此时可以开门
						that.canOpenDoor = true
						console.log('变换按钮')
					}, null, true)
			},
			goHome() {
				uni.navigateTo({
					url: '/pages/userhome'
				})
			},
		}
	}
</script>

<style>

	.-openDoor-body>view {
		border-radius: 1ex;
	}

	.-openDoor-body {
		position: fixed;
		top: 240px;
		padding: 15px 20px;
		width: calc(100% - 40px);
		z-index: -1;
		height: calc(100vh - 195px);
	}

	.roomInfo {
		margin-bottom: 20px;
		/* background-color: rgba(255, 255, 255, .5); */
		background-color: white;
		border-radius: 1ex;
		z-index: 88;
	}

</style>